<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h1>todolist</h1>
      <input type="text" v-model="value" />
      <button @click="add">添加</button>

      <ul>
        <li v-for="item in list" :key="item.id">
          {{item.name}}
          <button @click="remove(item.id)">删除</button>
        </li>
      </ul>

      <hr />

      <p>count: {{count}}</p>
      <button @click="increment">count++</button>

      <hr />

      <ul ref="ul">
        <li v-for="item in arr" :key="item.id">{{ item.nm }}</li>
      </ul>
    </div>

    <script src="../Vue.js"></script>

    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            value: "",
            list: [{ id: 1, name: "zhangsan" }],
            count: 0,
            arr: [],
          };
        },
        methods: {
          add() {
            this.list.push({ id: new Date().getTime(), name: this.value });
            this.value = "";
          },
          remove(id) {
            this.list = this.list.filter((item) => item.id !== id);
          },
          increment() {
            this.count++;
          },
        },
        mounted() {
          fetch("http://101.35.148.193:3000/api/rated/list")
            .then((response) => response.json())
            .then((res) => {
              this.arr = res.data;
            });

          this.count = 10;
        },
      }).mount("#app");
    </script>
  </body>
</html>
